<?php
        include_once("funciones/utilities.php");
        include_once("funciones/configuracion.php");
        include_once("funciones/consulta.php");
        include_once("funciones/tf-idf.php");
        
		if(!isset($_POST['btnG']))
{											
?>
<html class="no-js" lang="en"> <!--<![endif]-->
<head>

    <meta http-equiv="Content-Type" 
                   content="text/html; charset=UTF-8">

    <title></title>

    <meta name="description" content="" />
    
     <!-- Mobile viewport optimized: j.mp/bplateviewport -->
 	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
    
    <link href="style.css" rel="stylesheet" />
    <link href="http://fonts.googleapis.com/css?family=Droid+Serif:regular,bold" rel="stylesheet" /> <!-- Load Droid Serif from Google Fonts -->
    
    <!-- All JavaScript at the bottom, except for Modernizr and Respond.
    	Modernizr enables HTML5 elements & feature detects; Respond is a polyfill for min/max-width CSS3 Media Queries -->
    <script src="js/modernizr-1.7.min.js"></script>
    <script src="js/respond.min.js"></script>
    <script src="js/javascripts.js"></script>
</head>

<body>

<div id="wrapper">


    
    <div id="content" role="main">
    
		<center> 
<FORM method="post" action=""> 
<TABLE bgcolor="#FFFFFF"><tr><td> 
<!--<A HREF="http://www.google.com/"> 
<IMG SRC="http://www.google.com/logos/Logo_40wht.gif" border="0" ALT="Google" align="absmiddle"></A> -->
<INPUT TYPE="text" name="q" size="52" maxlength="255" value=""> 
<INPUT TYPE="hidden" name="hl" value="es"> 
<INPUT type="submit" name="btnG" value="Consultar"> 
</td></tr></TABLE> 
</FORM>

    </div> <!-- #content -->
    
    
</div> <!-- #main -->
  
<div class="clear"></div>
</div> <!-- #wrapper -->
</body>
</html> 
<?php
}
	else
	{	
		if(isset($_POST['btnG']))
		{
			$stopwords_file = "stopwords.txt";
			$lista = explode(",", $_POST['q']);
			$nkey= count($lista);
			
			for($i=0; $i<$nkey; $i++)
				$lista[$i] = strtolower($lista[$i]);
				
			$p = array('/À/','/Â/','/Ã/','/Ä/','/Å/','/È/','/Ê/','/Ë/','/Ì/','/Î/','/Ï/','/Ò/','/Ô/','/Õ/','/Ö/','/Ø/','/Ù/','/Û/','/Ü/','/Á/','/É/','/Í/','/Ó/','/Ú/','/á/','/é/','/í/','/ó/','/ú/','/à/','/è/','/ì/','/ò/','/ù/','/â/','/ê/','/î/','/ô/','/û/','/ä/','/ë/','/ï/','/ö/','/ü/','/ã/','/å/','/õ/','/ø/','/ç/','/ÿ/','/Ñ/', '//', '/1/', '/2/', '/3/', '/4/', '/5/', '/6/', '/7/', '/8/', '/9/', '/0/');
			$r = array('a','a','a','a','a','e','e','e','i','i','i','o','o','o','o','o','u','u','u','a','e','i','o','u','a','e','i','o','u','a','e','i','o','u','a','e','i','o','u','a','e','i','o','u','a','a','o','o','c','y','ñ', '', '', '', '', '', '', '', '', '', '', '');
			
			for($i=0; $i<$nkey; $i++)
			{
				$lista[$i] = preg_replace($p, $r, $lista[$i]);
				$lista[$i] = preg_replace("/[^A-Za-z0-9 '\n'ñ]/","",$lista[$i]);
				$lista[$i] = str_replace("\n", " ", $lista[$i]);
				$lista[$i] = str_replace("\r", " ", $lista[$i]);
				$lista[$i] = str_replace("\b", " ", $lista[$i]);
				$lista[$i] = str_replace("\t", " ", $lista[$i]);
				$lista[$i] = stop_words($lista[$i], $stopwords_file);
				$lista[$i] = quitar_espacios_dobles($lista[$i]);                                       
			}
			
			//Quitar los espacios que quedan cuando en la consulta un palabra clave es un stopword.
			for($i=0; $i<$nkey; $i++)
				if($lista[$i]  == "")
					unset($lista[$i]);
					
			$urls=listar_directorios_ruta("archivosLimpios");
					
			$lista = array_values($lista);
			//var_dump($lista);
			$listacontenido=cargarContenido();
			//var_dump($listacontenido);
			$tf= tf($listacontenido,$lista);
			//var_dump($tf);
			$df= df($listacontenido,$lista,$tf);
			//var_dump();
			$idf= idf($lista,$df,$listacontenido);
			//var_dump();
			$matriz=matrizW($listacontenido, $lista, $tf, $idf);
			//var_dump();
			initconsulta(count($lista),$matriz,$urls);
			
			?>
				<!DOCTYPE html>
				<html class="no-js" lang="en"> <!--<![endif]-->
					<head>
					   <link href="funciones/tablecss.css" rel="stylesheet" />
			
						<meta http-equiv="Content-Type" 
									content="text/html; charset=UTF-8">

						<title></title>

						<meta name="description" content="" />

						<!-- Mobile viewport optimized: j.mp/bplateviewport -->
							<meta name="viewport" content="width=device-width, initial-scale=1.0" />

						<link href="style.css" rel="stylesheet" />
						<link href="http://fonts.googleapis.com/css?family=Droid+Serif:regular,bold" rel="stylesheet" /> <!-- Load Droid Serif from Google Fonts -->

						<!-- All JavaScript at the bottom, except for Modernizr and Respond.
							Modernizr enables HTML5 elements & feature detects; Respond is a polyfill for min/max-width CSS3 Media Queries -->
						<script src="js/modernizr-1.7.min.js"></script>
						<script src="js/respond.min.js"></script>
					</head>
					<body>
						<nav id="menu" class="clearfix" role="navigation">
							
							<li><a href="busqueda.php">Regresar</a></li>                                            
							
						</nav>
					</body>
				</html>

<?php
		}
	}
	

?>
